/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/

private ["_helo","_callsign","_heloNewStation","_mkrname","_mkrname2","_stgtar","_pos","_pilot","_grp","_dist1","_helo_marker_distance","_markerpos","_wpAH","_mtype","_helo_height"];

/* variables defined */
_helo = _this select 0;
_callsign = _this select 1;
_heloNewStation = true;
RUM_ASclick = false;

/* forces the server side helo object to become client side. */
[_helo] joinSilent player;
[_helo] joinSilent grpNull;

/* moves station marker points based on unique named id */
_mkrname = format ["%1station", _helo];
_mkrname2 = format ["%1station2", _helo];
_stgtar = format ["'%1' setMarkerPos _pos,'%2' setMarkerPos _pos,RUM_ASclick = true",_mkrname,_mkrname2];

/* opens map to define new station area */
openMap [true,true];
onMapSingleClick _stgtar;
titleText ["Select a new Station Point", "PLAIN DOWN"];
waitUntil {RUM_ASclick};
onMapSingleClick "";
titleFadeOut 0;
sleep 1;

/* closes map after map selection */
openMap [false,false];
RUM_ASclick = false;

/* gets position of new stationed area and defines the pilot of the helo */
_pos = getmarkerpos _mkrname;
_pilot = driver _helo;
_grp = group _pilot;
[_helo] joinSilent _grp;


/* set combat mode and behavior */
_helo setBehaviour "SAFE";
_helo setCombatMode "GREEN";

/* dialog from pilot to player */
["movestation",[player,_pilot,_callsign,_pos]] execVM (RUM_PATH+"AHel\radiodialogs.sqf");
 sleep 5;

/* sets up distance monitoring */
_markerpos = getmarkerpos _mkrname;
_helo_marker_distance = _markerpos distance [getPos _helo select 0, getPos _helo select 1, 0];
_dist1 = round _helo_marker_distance;

/* creates waypoints for the helo to follow and sets priority on speed based on distance */
if ((_dist1) <= 1300) then {
	_wpAH = _grp addWaypoint [_pos, 0];
	_wpAH setWaypointType "MOVE";
	_wpAH setWaypointSpeed "NORMAL";
	_wpAH setWaypointBehaviour "CARELESS";
	_wpAH setWaypointCombatMode "BLUE";
	_wpAH setWaypointCompletionRadius 0;
	_helo flyInheight 32;

	sleep 4.75;
	deleteWaypoint [_grp, 0];

	_wpAH = _grp addWaypoint [_pos, 0];
	_wpAH setWaypointType "MOVE";
	_wpAH setWaypointSpeed "LIMITED";
	_wpAH setWaypointBehaviour "CARELESS";
	_wpAH setWaypointCombatMode "BLUE";
	_wpAH setWaypointCompletionRadius 0;
	_helo flyInheight 45;

	sleep 5;
	deleteWaypoint [_grp, 0];
} else {
	_wpAH = _grp addWaypoint [_pos, 0];
	_wpAH setWaypointType "MOVE";
	_wpAH setWaypointSpeed "NORMAL";
	_wpAH setWaypointBehaviour "CARELESS";
	_wpAH setWaypointCombatMode "BLUE";
	_wpAH setWaypointCompletionRadius 0;
	_helo flyInheight 32;

	sleep 4.75;
	deleteWaypoint [_grp, 0];

	_wpAH = _grp addWaypoint [_pos, 0];
	_wpAH setWaypointType "MOVE";
	_wpAH setWaypointSpeed "NORMAL";
	_wpAH setWaypointBehaviour "CARELESS";
	_wpAH setWaypointCombatMode "BLUE";
	_wpAH setWaypointCompletionRadius 0;
	_helo flyInheight 70;

	sleep 5;
	deleteWaypoint [_grp, 0];
};

/* waypoint that settles the helo at the new station point */
while {_heloNewStation} do {
	if ((_helo_marker_distance) <= 150) then {
		_wpAH = _grp addWaypoint [_pos, 0];
		_wpAH setWaypointType "MOVE";
		_wpAH setWaypointSpeed "NORMAL";
		_wpAH setWaypointBehaviour "CARELESS";
		_wpAH setWaypointCombatMode "BLUE";
		_wpAH setWaypointCompletionRadius 0;
		_helo flyInheight RUM_AHEL_flyStationHeight;
		sleep 5;
		deleteWaypoint [_grp, 0];
		_heloNewStation = false;
	} else {
		If (!alive _helo) then {
			player sidechat "Helo has crashed or has been shot down.";
			_heloNewStation = false;
			exit;	
		} else {
			_helo_marker_distance = round (_markerpos distance [getPos _helo select 0, getPos _helo select 1, 0]);
			_helo_height = round (getPos _helo select 2);
			sleep 0.15;
		};
	};
};

/* waits till the helo has reached the new location */
waituntil{
	((getPos _helo select 2) <= (RUM_AHEL_flyStationHeight + 30));
};

/* dialog to player */
_pilot sidechat format["This is %1, station position reached.", _callsign ];
sleep 4;

/* exits script */
if(true)exitwith{};
